<template>
	<view>
		<template v-for="goods in goodslist">

			<goods :goods="goods"></goods>

		</template>
	</view>
</template>

<script>
	import {
		http
	} from '@/utils/http.js'
	import {
		ref,
		toRefs,
		reactive,
		onMounted
	} from 'vue';
	export default {
		setup() {
			const goodslist = ref([1, 2, 3, 4, 5]);

			const token = uni.getStorageSync("token");

			//拦截器，判断是否存在token
			uni.addInterceptor("request", {
				invoke(args) {
					const token = uni.getStorageSync("token");
					//没登陆
					if (!token) {
						// console.log(args)
						uni.reLaunch({
							url: "/pages/login/login"
						})
					}
				}
			})

			onMounted(() => {
				getData();
			})

			const getData = () => {
				http("/goods/goodsList", "get", {}, token).then(res => {
					console.log(res);
					goodslist.value = res.data.data;
				}).catch(err => {
					console.log(err);
				})
			}

			return {
				goodslist
			}

		}
	}
</script>

<style scoped>

</style>
